package main

import (
	"fmt"
	"log"
	"os"

	"github.com/gin-gonic/gin"
	"gitlab.com/go-course-project/go17/book/api"
	"gitlab.com/go-course-project/go17/book/config"
)

// 规定好风格: JSON Restful Api
func main() {
	// 从配置文件中加载配置
	// 加载配置
	path := os.Getenv("CONFIG_PATH")
	if path == "" {
		path = "application.yaml"
	}
	if err := config.LoadConfigFromYaml(path); err != nil {
		fmt.Printf("加载配置错误: %s\n", err)
		os.Exit(1)
	}
	// 访问加载后的配置
	conf := config.Get()

	// gin Engine, 它包装了http server
	server := gin.Default()
	api.NewBookHandler().Registry(server)

	if err := server.Run(conf.App.Address()); err != nil {
		log.Println(err)
	}
}
